﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.ComponentModel.DataAnnotations;
using WalkingTec.Mvvm.Core;
using WalkingTec.Mvvm.Core.Extensions;
using Digitalmes.Model.PlanningManagement;
using Digitalmes.Model;

namespace Digitalmes.ViewModel.PlanningManagement.ProductionTaskVMs
{
    public partial class ProductionTaskListVM : BasePagedListVM<ProductionTask_View, ProductionTaskSearcher>
    {
        
        protected override IEnumerable<IGridColumn<ProductionTask_View>> InitGridHeader()
        {
            return new List<GridColumn<ProductionTask_View>>{
                
                this.MakeGridHeader(x => x.ProductionTask_Wo).SetTitle(@Localizer["Page.工单"].Value),
                this.MakeGridHeader(x => x.ProductionTask_ProdOrder).SetTitle(@Localizer["Page.关联订单"].Value),
                this.MakeGridHeader(x => x.ProductionTask_ProductId).SetTitle(@Localizer["Page.产品"].Value),
                this.MakeGridHeader(x => x.ProductionTask_ProductCode).SetTitle(@Localizer["Page.产品名称"].Value),
                this.MakeGridHeader(x => x.ProductionTask_ProductName).SetTitle(@Localizer["Page.产品名称"].Value),
                this.MakeGridHeader(x => x.ProductionTask_LineId).SetTitle(@Localizer["Page.产线"].Value),
                this.MakeGridHeader(x => x.ProductionTask_LineCode).SetTitle(@Localizer["Page.产线编码"].Value),
                this.MakeGridHeader(x => x.ProductionTask_OpId).SetTitle(@Localizer["Page.工位"].Value),
                this.MakeGridHeader(x => x.ProductionTask_OpCode).SetTitle(@Localizer["Page.工位号"].Value),
                this.MakeGridHeader(x => x.ProductionTask_ShiftId).SetTitle(@Localizer["Page.班次"].Value),
                this.MakeGridHeader(x => x.ProductionTask_ShiftCode).SetTitle(@Localizer["Page.班次代号"].Value),
                this.MakeGridHeader(x => x.ProductionTask_ProductionBatch).SetTitle(@Localizer["Page.生产批次"].Value),
                this.MakeGridHeader(x => x.ProductionTask_TaskStatus).SetTitle(@Localizer["Page.任务状态"].Value),
                this.MakeGridHeader(x => x.ProductionTask_PlanQty).SetTitle(@Localizer["Page.计划数量"].Value),
                this.MakeGridHeader(x => x.ProductionTask_OnlineQty).SetTitle(@Localizer["Page.上线数量"].Value),
                this.MakeGridHeader(x => x.ProductionTask_QualifiedQty).SetTitle(@Localizer["Page.合格数量"].Value),
                this.MakeGridHeader(x => x.ProductionTask_UnqualifiedQty).SetTitle(@Localizer["Page.不合格数量"].Value),
                this.MakeGridHeader(x => x.ProductionTask_ScrapQty).SetTitle(@Localizer["Page.报废数量"].Value),
                this.MakeGridHeader(x => x.ProductionTask_CompletedQty).SetTitle(@Localizer["Page.完工数量"].Value),
                this.MakeGridHeader(x => x.ProductionTask_CreateTime).SetTitle(@Localizer["_Admin.CreateTime"].Value),
                this.MakeGridHeader(x => x.ProductionTask_UpdateTime).SetTitle(@Localizer["_Admin.UpdateTime"].Value),
                this.MakeGridHeader(x => x.ProductionTask_CreateBy).SetTitle(@Localizer["_Admin.CreateBy"].Value),
                this.MakeGridHeader(x => x.ProductionTask_UpdateBy).SetTitle(@Localizer["_Admin.UpdateBy"].Value),

                this.MakeGridHeaderAction(width: 200)
            };
        }

        
        public override IOrderedQueryable<ProductionTask_View> GetSearchQuery()
        {
            var query = DC.Set<ProductionTask>()
                
                .CheckContain(Searcher.Wo, x=>x.Wo)
                .CheckEqual(Searcher.ProdOrderId, x=>x.ProdOrderId)
                .CheckEqual(Searcher.ProductId, x=>x.ProductId)
                .CheckContain(Searcher.ProductCode, x=>x.ProductCode)
                .CheckContain(Searcher.ProductName, x=>x.ProductName)
                .CheckEqual(Searcher.LineId, x=>x.LineId)
                .CheckContain(Searcher.LineCode, x=>x.LineCode)
                .CheckEqual(Searcher.OpId, x=>x.OpId)
                .CheckContain(Searcher.OpCode, x=>x.OpCode)
                .CheckEqual(Searcher.ShiftId, x=>x.ShiftId)
                .CheckContain(Searcher.ShiftCode, x=>x.ShiftCode)
                .CheckContain(Searcher.ProductionBatch, x=>x.ProductionBatch)
                .CheckEqual(Searcher.TaskStatus, x=>x.TaskStatus)
                .CheckEqual(Searcher.PlanQty, x=>x.PlanQty)
                .CheckEqual(Searcher.OnlineQty, x=>x.OnlineQty)
                .CheckEqual(Searcher.QualifiedQty, x=>x.QualifiedQty)
                .CheckEqual(Searcher.UnqualifiedQty, x=>x.UnqualifiedQty)
                .CheckEqual(Searcher.ScrapQty, x=>x.ScrapQty)
                .CheckEqual(Searcher.CompletedQty, x=>x.CompletedQty)
                .CheckBetween(Searcher.CreateTime?.GetStartTime(), Searcher.CreateTime?.GetEndTime(), x => x.CreateTime, includeMax: false)
                .CheckBetween(Searcher.UpdateTime?.GetStartTime(), Searcher.UpdateTime?.GetEndTime(), x => x.UpdateTime, includeMax: false)
                .CheckContain(Searcher.CreateBy, x=>x.CreateBy)
                .CheckContain(Searcher.UpdateBy, x=>x.UpdateBy)
                .Select(x => new ProductionTask_View
                {
				    ID = x.ID,
                    
                    ProductionTask_Wo = x.Wo,
                    ProductionTask_ProdOrder = x.ProdOrder.TenantCode,
                    ProductionTask_ProductId = x.ProductId,
                    ProductionTask_ProductCode = x.ProductCode,
                    ProductionTask_ProductName = x.ProductName,
                    ProductionTask_LineId = x.LineId,
                    ProductionTask_LineCode = x.LineCode,
                    ProductionTask_OpId = x.OpId,
                    ProductionTask_OpCode = x.OpCode,
                    ProductionTask_ShiftId = x.ShiftId,
                    ProductionTask_ShiftCode = x.ShiftCode,
                    ProductionTask_ProductionBatch = x.ProductionBatch,
                    ProductionTask_TaskStatus = x.TaskStatus,
                    ProductionTask_PlanQty = x.PlanQty,
                    ProductionTask_OnlineQty = x.OnlineQty,
                    ProductionTask_QualifiedQty = x.QualifiedQty,
                    ProductionTask_UnqualifiedQty = x.UnqualifiedQty,
                    ProductionTask_ScrapQty = x.ScrapQty,
                    ProductionTask_CompletedQty = x.CompletedQty,
                    ProductionTask_CreateTime = x.CreateTime,
                    ProductionTask_UpdateTime = x.UpdateTime,
                    ProductionTask_CreateBy = x.CreateBy,
                    ProductionTask_UpdateBy = x.UpdateBy,
                })
                .OrderBy(x => x.ID);
            return query;
        }

        
    }
    public class ProductionTask_View: ProductionTask
    {
        
        public string ProductionTask_Wo { get; set; }
        public string ProductionTask_ProdOrder { get; set; }
        public long? ProductionTask_ProductId { get; set; }
        public string ProductionTask_ProductCode { get; set; }
        public string ProductionTask_ProductName { get; set; }
        public long? ProductionTask_LineId { get; set; }
        public string ProductionTask_LineCode { get; set; }
        public long? ProductionTask_OpId { get; set; }
        public string ProductionTask_OpCode { get; set; }
        public long? ProductionTask_ShiftId { get; set; }
        public string ProductionTask_ShiftCode { get; set; }
        public string ProductionTask_ProductionBatch { get; set; }
        public WoStatusEnum? ProductionTask_TaskStatus { get; set; }
        public decimal? ProductionTask_PlanQty { get; set; }
        public decimal? ProductionTask_OnlineQty { get; set; }
        public decimal? ProductionTask_QualifiedQty { get; set; }
        public decimal? ProductionTask_UnqualifiedQty { get; set; }
        public decimal? ProductionTask_ScrapQty { get; set; }
        public decimal? ProductionTask_CompletedQty { get; set; }
        public DateTime? ProductionTask_CreateTime { get; set; }
        public DateTime? ProductionTask_UpdateTime { get; set; }
        public string ProductionTask_CreateBy { get; set; }
        public string ProductionTask_UpdateBy { get; set; }

    }

}